package projectdemo01.operation;

import projectdemo01.book.Book;
import projectdemo01.book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 09 - 23
 * Time:19:49
 */

/***
 * 3.借阅图书——实现：修改图书的状态即可
 */
public class BorrowOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("借阅书籍");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要借阅图书的名字：");
        String bookname = scanner.nextLine();

        //遍历顺序表，根据输入的图书名字，找到之后，修改其状态
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(bookname)){//说明有这本书
                book.setStatus(true);//将此本书的借阅状态修改为true
                System.out.println(book);
                return;

            }
        }
        System.out.println("没有你要借阅的这本书！");
    }
}
